﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using System.Collections.ObjectModel;

// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238

namespace BlogReader
{
    /// <summary>
    /// An empty page that can be used on its own or navigated to within a Frame.
    /// </summary>
    public sealed partial class MainPage : Page
    {
        public static string HEADER = "List GF";
        public MainPage()
        {
            this.InitializeComponent();
        }

        /// <summary>
        /// Invoked when this page is about to be displayed in a Frame.
        /// </summary>
        /// <param name="e">Event data that describes how this page was reached.  The Parameter
        /// property is typically used to configure the page.</param>
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            /*
            FeedDataSource feedDataSource = (FeedDataSource)App.Current.Resources["feedDataSource"];
            if (feedDataSource != null)
            {
                this.DataContext = (feedDataSource.Feeds).ElementAt(2);
            }
            */
            
            Shrimps data = new Shrimps();
            for (int i = 0; i < 50; i++)
            {
                Shrimp newShrimp = new Shrimp("Thu Trang", "Phanh Anh", "Hoang Anh");
                data.ListShrimp.Add(newShrimp);
            }

            this.DataContext = data;
        }

        private void ItemListView_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (e.AddedItems.Count > 0)
            {
                FeedItem feedItem = e.AddedItems[0] as FeedItem;
                if (feedItem != null)
                {
                    ContentView.NavigateToString(feedItem.Content);
                }

            }
            else
            {
                ContentView.NavigateToString("");
            }
        }

        public class Shrimp
        {
            public string Title { get; set; }
            public string Author { get; set; }
            public string PubDate { get; set; }

            public Shrimp(string title, string author, string pub)
            {
                Title = title;
                Author = author;
                PubDate = pub;
            }
        }

        public class Shrimps
        {
            ObservableCollection<Shrimp> _ListShrimp = new ObservableCollection<Shrimp>();
            public ObservableCollection<Shrimp> ListShrimp
            {
                get
                {
                    return this._ListShrimp;
                }
            }
        }
    }
}
